package homework;

import java.util.*;

public class HomeText01 {
    //1.使用List和Map存放多个图书信息，遍历并输出。
    // 其中商品属性：编号，名称，单价，出版社；使用商品编号作为Map中的key。
    public static void main(String[] args) {
        List<Book> books = new ArrayList<>();
        Book b1 = new Book("1","java",100,"清华大学");
        Book b2 = new Book("2","c++",200,"北京大学");
        Book b3 = new Book("3","python",300,"上海大学");
        books.add(b1);
        books.add(b2);

        for (Book book : books) {
            System.out.println(book);
        }
        Map<String,Book> map = new HashMap<>();
        map.put(b1.getId(), books.get(0));
        map.put(b2.getId(),books.get(1));
        map.put(b3.getId(),books.get(2));
        for (Map.Entry<String, Book> bookBookEntry : map.entrySet()) {
            System.out.println(bookBookEntry.getKey()+"--"+bookBookEntry.getValue());
        }
    }
}
class Book{
    private String id;
    private String name;
    private double price;
    private String press;
    public Book(String id, String name, double price, String press) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.press = press;
    }

    public Book() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getPress() {
        return press;
    }

    public void setPress(String press) {
        this.press = press;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Book book = (Book) o;
        return Double.compare(book.price, price) == 0 && Objects.equals(id, book.id) && Objects.equals(name, book.name) && Objects.equals(press, book.press);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, price, press);
    }

    @Override
    public String toString() {
        return "编号："+id+"  名称："+name+"  单价："+price+"  出版社："+press;
    }
}

